#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 200005;
int t, n, k, len;
int a[N], b[N];
int main(){
	cin >> t;
	while(t--){
		memset(b, 0, 4 * (len + 1));
		len = 0;
		cin >> n >> k;
		for (int i = 0; i < n; i++) cin >> a[i];
		sort(a, a + n);
		for (int i = 1; i < n; i++){
			if (abs(a[i - 1] - a[i]) <= k){
				b[len]++;
			}
			else len++;
		}
		sort (b, b + len + 1);
		cout << n - (b[len] + 1) << endl;
		
		
	}

    return 0;
}


